package com.hexinfo.dmpro.sparing.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.sql.DataSource;

/**
 * 删除两年前日期分区数据
 * drop连接池配置
 *
 */

@Configuration
@Slf4j
public class DropThreadPoolConfig {

	@Value("${thread.pool.drop.threadNamePrefix}")
	private String threadNamePrefix;
	@Value("${thread.pool.drop.queueCapacity}")
	private int queueCapacity;
	@Value("${thread.pool.drop.corePoolSize}")
	private int corePoolSize;
	@Value("${thread.pool.drop.maxPoolSize}")
	private int maxPoolSize;
	@Value("${thread.pool.drop.keepAliveSeconds}")
	private int keepAliveSeconds;
	@Value("${thread.pool.drop.rejectedExecutionHandler}")
	private String rejectedExecutionHandler;

	@Bean(name = "dropTaskExecutor")
	public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
		log.info("drop线程池初始化开始");
		ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
		pool.setThreadNamePrefix(threadNamePrefix); //线程前缀
		pool.setQueueCapacity(queueCapacity); // 队列容量
		pool.setCorePoolSize(corePoolSize); // 核心线程池数
		pool.setMaxPoolSize(maxPoolSize); // 最大线程
		pool.setKeepAliveSeconds(keepAliveSeconds); //线程空闲时间
		pool.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); // 队列满，线程被拒绝执行策略
		//执行初始化
		pool.initialize();
		return pool;
	}
 
}